CC=/usr/bin/gcc
CFLAGS=-O2 -pipe -march=native -g -Wno-int-to-pointer-cast -Wno-incompatible-pointer-types -Wno-pointer-to-int-cast -pthread
TESTS=jmps test cmp rng

.PHONY: vm asm tests

SRC_DIR     := src
INCLUDE_DIR := ${SRC_DIR}/include

VM_SRC    := ${SRC_DIR}/util.c ${SRC_DIR}/vm.c

ASM_SRC   := ${SRC_DIR}/util.c ${SRC_DIR}/asm.c

all: vm asm
threads:
	${CC} ${CFLAGS} ${SRC_DIR}/threads.c -o threads -ldl -Wl,--export-dynamic
vm:
	${CC} ${CFLAGS} ${VM_SRC} -o vm -ldl -Wl,--export-dynamic
asm:
	${CC} ${CFLAGS} ${ASM_SRC} -o asm
tests:
	${foreach file,${TESTS},./asm "tests/${file}.48" "tests/${file}.bin";}
video:
	${CC} ${CFLAGS} -I /usr/include/SDL2 -c -fpic ${SRC_DIR}/video.c 
	${CC} ${CFLAGS} -shared video.o -o video.ho48 -L/usr/lib/x86_64-linux-gnu/ -lSDL2 -lSDL2_ttf
	rm -f video.o
rng:
	${CC} ${CFLAGS} -c -fpic ${SRC_DIR}/rng.c
	${CC} ${CFLAGS} -shared rng.o -o rng.ho48
